package javabase.schoolwork.day5_23;

import java.util.Scanner;

/**
 * @author fance
 * @date 2018/5/23 20:41
 */
public class Solution {
    public static void main(String[] args) {
        /*final long m=24*60*60*1000*1000L;//加L才是long类型
        final long n=24*60*60*1000L;//不加L会溢出
        System.out.println(m / n);*/
        // printPascalTriangle();
        calendar();
    }

    public static double calFee(double weight,double dist,double fee) {
        if (weight < 0 || dist < 0) {
            return -1;
        }
        double cost = 0;
        if (dist < 500) {}
        else if (dist < 1000) {
            cost = weight * dist * fee * 0.95;
        } else if(dist < 1500) {
            cost = weight * dist * fee * 0.92;
        }else if(dist<2500) {
            cost = weight*dist*fee*0.90;
        }else if(dist >= 2500) {
            cost = weight*dist*fee*0.88;
        }
        return cost;
    }


    public static void printPascalTriangle() {
        int[][] a = new int[10][10];
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j <= i; j++) {
                if (j == 0 || j == i) {
                    a[i][j] = 1;
                } else {
                    a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
                }
            }
        }
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j <= i; j++) {
                System.out.print(a[i][j] + " ");
            }
            System.out.println();
        }
    }

    public static void calendar() {
        Scanner scanner = new Scanner(System.in);
        int year = scanner.nextInt();
        int month = scanner.nextInt();
        int[] days = {31,28,31,30,31,30,31,31,30,31,30,31};
        int dayCount = 0;
        // 之前年份所有天数
        for (int i = 1900; i < year; i++) {
            dayCount += 365;
            if (isRunYear(i)) {
                dayCount++;
            }
        }

        // 计算今年
        if(isRunYear(year)) {
            days[1] = 29;
        }
        for (int i = 0; i < month - 1; i++) {
            dayCount += days[i];
        }

        // 计算月份第一天星期几
        int weekDay = 1 + dayCount % 7;

        for (int i = 0; i < 7; i++) {
            System.out.print("星期" + i + "\t");
        }
        System.out.println();
        for (int i = 0; i < weekDay; i++) {
            System.out.print("\t\t");
        }
        for (int i = 1; i <= days[month - 1]; i++) {
            System.out.print(i + "\t\t");
            weekDay++;
            if (weekDay == 7) {
                System.out.println();
                weekDay = 0;
            }
        }
    }
    public static boolean isRunYear(int year) {
        return year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
    }


}
